package com.wgj.android.adapter;
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jiaai.xui.utils.XDateUtils;
import com.wgj.android.R;
import com.wgj.android.entity.Group;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
 * ========================================
 * 作    者： 佳爱网络有限公司(wwww.jiaailove.com)
 * 版    本： 1.0
 * 创建日期：  2017/12/6
 * 描    述：
 * 修订历吏：
 * =========================================
 */
public class GroupAdapter extends BaseAdapter<Group,GroupAdapter.GroupHolder> {
    private  Context mContext;
    private  List<Group> groups=new ArrayList<>();
    public GroupAdapter(Context context,List<Group> groups) {
        super(context);
        this.mContext=context;
        this.groups=groups;
    }

    @Override
    public void addItem(Group group) {
         groups.add(group);
         notifyDataSetChanged();
    }

    @Override
    public void notifyDataSetChanged(List<Group> dataList) {
            groups.clear();
            groups.addAll(dataList);
            notifyDataSetChanged();
    }


    @Override
    public GroupHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new GroupHolder(LayoutInflater.from(mContext).inflate(R.layout.group_item_view,parent,false));
    }

    @Override
    public void onBindViewHolder(GroupHolder holder, int position) {
            holder.bindData(groups.get(position));
    }

    @Override
    public int getItemCount() {
        return groups.size();
    }

    static class GroupHolder extends RecyclerView.ViewHolder  {
          TextView tvGroupName;
          TextView tvNumber;
          TextView tvSynchroStatus;
          TextView tvSynchroTime;
         public GroupHolder(View itemView) {
            super(itemView);
            tvGroupName=itemView.findViewById(R.id.groupName);
//            tvNumber=itemView.findViewById(R.id.number);
//            tvSynchroStatus=itemView.findViewById(R.id.synchroStatus);
//            tvSynchroTime=itemView.findViewById(R.id.synchroTime);

        }

        public void bindData(Group group){
            tvGroupName.setText(group.getGroupname());
//            if(group.getSynchroStatus()==1){
//                tvSynchroStatus.setText("已同步");
//                tvSynchroTime.setText("同步时间:"+XDateUtils.date2String(new Date(group.getSynchroTime())));
//                tvSynchroTime.setVisibility(View.VISIBLE);
//            }else {
//                tvSynchroStatus.setText("未同步");
//                tvSynchroTime.setVisibility(View.GONE);
//            }


        }
    }
}
